<?php

/**
 * This is the model class for table "{{adviser}}".
 *
 * The followings are the available columns in table '{{adviser}}':
 * @property integer $id
 * @property string $username
 * @property string $job
 * @property string $nation
 * @property string $birthday
 * @property string $education
 * @property string $info
 * @property string $photo
 * @property integer $status
 * @property integer $order
 * @property string $mktime
 */
class Adviser extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Adviser the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{adviser}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mktime,username', 'required'),
			array('status, order', 'numerical', 'integerOnly'=>true),
			array('username, job', 'length', 'max'=>64),
			array('nation, education', 'length', 'max'=>32),
			array('birthday, mktime', 'length', 'max'=>10),
//			array('photo', 'length', 'max'=>255),
            array('photo', 'file', 'types'=>'jpg,gif', 'maxSize'=>1024*1024, 'allowEmpty'=>TRUE),
			array('info', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, username, job, nation, birthday, education, info, photo, status, order, mktime', 'safe', 'on'=>'search'),
            array('username, job, nation, birthday, education, info, photo, status, order, mktime', 'safe'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
            'username' => '姓名',
            'job' => '职位',
            'nation' => '民族',
            'birthday' => '出生日期',
            'education' => '学历学位',
            'info' => '简介',
            'photo' => '头像',
            'status' => '状态',
            'order' => '排序',
            'mktime' => '创建时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('job',$this->job,true);
		$criteria->compare('nation',$this->nation,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('education',$this->education,true);
		$criteria->compare('info',$this->info,true);
		$criteria->compare('photo',$this->photo,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('order',$this->order);
		$criteria->compare('mktime',$this->mktime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}